package temaihui.daimaitemai;

import android.content.Context;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONObject;

/**
 * Created by sun on 16/7/28.
 */
public class RequestAction {


    public static void sendRequest(Context context, String actionName,JSONObject data,final Response.Listener<JSONObject> reponseListener,final Response.ErrorListener errorListener){
        RequestQueue mQueue = Volley.newRequestQueue(context);
        String url = "http://139.196.203.19:8081/tmh-new/"+actionName;
        JSONObject requestData = new JSONObject();

        try {
            requestData.put("category", "1");
            requestData.put("version", "1");
            requestData.put("token", "ad8440fc7b114f8a93c49f5f7fe153ca");
            requestData.put("platform", "2");
            requestData.put("data",data);
        } catch (Exception e) {

        }
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST,url, requestData, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                reponseListener.onResponse(jsonObject);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                errorListener.onErrorResponse(volleyError);

            }
        });
        mQueue.add(request);
    }
}
